package com.ljfiction.book.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;

import com.ljfiction.book.Baner.MyPurseRecycalerbean;

import com.ljfiction.book.MyView.SuperButton;
import com.ljfiction.book.R;
import com.ljfiction.book.http.HttpManager;
import com.ljfiction.book.http.UserBean;
import com.ljfiction.book.http.UserManageBean;
import com.ljfiction.book.tools.AppUtils;
import com.ljfiction.book.tools.SettingManager;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;


public class MyPursActivity extends BaseActivity {

    @BindView(R.id.back_purse)
    ImageView backPurse;
    @BindView(R.id.jiaoyijilu)
    TextView jiaoyijilu;
    @BindView(R.id.peppernum_purse)
    TextView peppernumPurse;
    @BindView(R.id.dingwei1)
    TextView dingwei1;
    @BindView(R.id.recharge_purse)
    SuperButton rechargePurse;
    @BindView(R.id.jinjiaonum)
    TextView jinjiaonum;
    @BindView(R.id.songjinjiao)
    TextView songjinjiao;
    @BindView(R.id.xiaomijiaonum)
    TextView xiaomijiaonum;
    @BindView(R.id.songxiaomijiao)
    TextView songxiaomijiao;
    @BindView(R.id.daijinjuannum)
    TextView daijinjuannum;
    @BindView(R.id.songdaijinjuan)
    TextView songdaijinjuan;


    private List<MyPurseRecycalerbean.MyPurseRecycalerItembean> datas = new ArrayList<>();
    private Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_purs);
        ButterKnife.bind(this);
        initView();
        intdata();
    }

    private void intdata() {
        OkHttpUtils.post(HttpManager.IP+"/person-info")

                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        Gson gson = new Gson();
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            if ("200".equals(jsonObject.getString("returnCode"))) {
                                UserBean user = gson.fromJson(jsonObject.getString("data"), UserBean.class);
                                UserManageBean.userBean = user;
                                UserManageBean.setIsLogin(true);
                                initView();
                            } else {

                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    private void initView() {
        peppernumPurse.setText(String.valueOf(UserManageBean.userBean.getUserMoney()));
        jinjiaonum.setText(String.valueOf(UserManageBean.userBean.getUserGoldenTicket()));
        xiaomijiaonum.setText(String.valueOf(UserManageBean.userBean.getUserRecommendTicket()));
        daijinjuannum.setText(String.valueOf(UserManageBean.userBean.getUserReadTicket()));
        datas = new MyPurseRecycalerbean().getDatas();
    }

    @OnClick({R.id.back_purse, R.id.jiaoyijilu, R.id.recharge_purse})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_purse:
                goBack();
                break;
            case R.id.jiaoyijilu:
                intent = new Intent(MyPursActivity.this, TransactionRecordActivity.class);
                startActivity(intent);
                break;
            case R.id.recharge_purse:
                Intent intent=new Intent(MyPursActivity.this,PursActivity.class);
                startActivity(intent);

                break;
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        initView();
    }




}
